<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            position: relative;
            /* height: 3000px; */
        }
        
        #nav {
            width: 100%;
            height: 60px;
            background-color: aquamarine;
            position: fixed;
            left: 0;
            top: -60px;
            transition: all 1s;
        }
        
        #footer {
            width: 50px;
            height: 50px;
            background-color: pink;
            position: fixed;
            right: 30px;
            bottom: 30px;
            cursor: pointer;
        }
        
        p {
            color: white;
            text-align: center;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div id="nav">
        <p>导航栏</p>
    </div>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <h2>新新新新新</h2>
    <div id="footer">
        <p>返回顶部</p>
    </div>
    <script>
        window.onscroll = function() {
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            if (scrollTop < 300) {
                nav.style.top = '-60px'
            } else {
                nav.style.top = 0
            }
        }
        footer.onclick = function() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            })
        }
    </script>
</body>

</html>